package com.bw.car.controller;

import com.bw.car.domain.Cars;
import com.bw.car.domain.Passageway;
import com.bw.car.feign.CarFeign;
import com.bw.car.service.CarsService;
import com.bw.car.units.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ooxml.util.PackageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarsService carsService;
    @Autowired
    private CarFeign carFeign;
    @RequestMapping("/list")
    public Result list(Integer current,Integer size){
        PageHelper.startPage(current,size);
        List<Cars> list = carsService.list();
        return Result.success(new PageInfo<>(list));
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Cars cars){
        boolean save = carsService.save(cars);
        return save?Result.success():Result.fail();
    }
    @RequestMapping("/chulist")
    public Result chulist(){
        List<Passageway> chu = carFeign.chu();
        return Result.success(chu);
    }
    @RequestMapping("/rulist")
    public Result rulist(){
        List<Passageway> ru = carFeign.ru();
        return Result.success(ru);
    }
}
